package com.taxer.service.impl;

import com.taxer.db.dao.AdminMapper;
import com.taxer.db.dao.TaxerMapper;
import com.taxer.db.entity.Admin;
import com.taxer.db.entity.Taxer;
import com.taxer.exception.TaxerExcepiton;
import com.taxer.service.TaxerService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service("taxerservice")
public class TaxerServiceImpl implements TaxerService {
    @Resource
    private TaxerMapper taxerMapper;
    @Resource
    private AdminMapper adminMapper;
    @Override
    public void insert(Taxer taxer) throws TaxerExcepiton {
        java.util.Date  date=new java.util.Date();
        java.sql.Date  data1=new java.sql.Date(date.getTime());
        Admin admin = new Admin();
        admin.setUsername("20000");
        admin.setPassword("123456");
        admin.setStatus((byte) 2);
        admin.setCreated(data1);
        admin.setUpdated(data1);
        adminMapper.insertSelective(admin);
        Admin aa=adminMapper.selectByName("20000");
        aa.setUsername("20000"+aa.getId());
        adminMapper.updateByPrimaryKey(aa);

        taxer.setCreated(data1);
        taxer.setUpdated(data1);
        taxer.setAdminId(aa.getId());
        taxerMapper.insert(taxer);
    }

    @Override
    public void update(Taxer taxer) throws TaxerExcepiton {
        taxerMapper.updateByPrimaryKey(taxer);
    }

    @Override
    public List<Taxer> getAllTaxer() throws TaxerExcepiton {
        List<Taxer> list=taxerMapper.findAll();
        return list;
    }

    @Override
    public Taxer getByName(String name) throws TaxerExcepiton {
        Taxer taxer=taxerMapper.findByName(name);
        return taxer;
    }

    @Override
    public void deleById(Long id) throws TaxerExcepiton {
        taxerMapper.deleteByPrimaryKey(id);
    }
}
